$(function () {
   var fileId= utils.getParameter("fileId");
    $("#jqGrid").jqGrid({
        url: '../sys/upload/list?urlType=0&&fileId='+fileId,
        datatype: "json",
        colModel: [
			{ label: 'id', name: 'id',width: 20, key: true ,hidden:true},
            { label: '文件名称', name: 'fileName',width: 40 },
            { label: 'URL地址', name: 'url',width: 160 },
			{ label: '创建时间', name: 'createDate', width: 40 },
            { label: '操作', width: 40,formatter: download}
        ],
		viewrecords: true,
        height: 385,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    })
});

var vm = new Vue({
	el:'#rrapp',
	data:{
		showList: true,
		title: null,
        config: {}
	},
	methods: {
		query: function () {
			vm.reload();
		},
        del: function () {
            var ossIds = getSelectedRows();
            if(ossIds == null){
                return ;
            }
            confirm('确定要删除选中的记录？', function(){
                $.ajax({
                    type: "POST",
                    url: "../sys/upload/delete",
                    contentType: "application/json",
                    data: JSON.stringify(ossIds),
                    success: function(r){
                        if(r.code === 0){
                            alert('操作成功', function(){
                                vm.reload();
                            });
                        }else{
                            alert(r.msg);
                        }
                    }
                });
            });
        },
		reload: function () {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{ 
                page:page
            }).trigger("reloadGrid");
		}
	}
});

$("#uploadwin").click(function(){
    utils.openDialogView('上传附件',$("#windowupload"),"500px","300px",1);
});
function download(cellvalue, options, rowObject){
    var html = "";
    html = "<a class='btn btn-primary' onclick='Click(\""+rowObject.id+"\")'>预览</a>";
    return html;

}
function Click(id){
    url="../sys/upload/download?id="+id;
    window.location.href=url;
}